package cn.com.css.taxInspection.gt3.service.impl;

import cn.com.css.taxInspection.gt3.entity.JcSrbcEntity;
import cn.com.css.taxInspection.gt3.mapper.JcSrbcMapper;
import cn.com.css.taxInspection.gt3.service.JcSrbcService;
import cn.com.css.taxInspection.util.TsBqUtils;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;


@Service("JcSrbcService")
public class JcSrbcServiceImpl extends ServiceImpl<JcSrbcMapper, JcSrbcEntity> implements JcSrbcService {

    @SuppressWarnings({"rawtypes", "unchecked"})
    @Override
    public IPage<JcSrbcEntity> querySrbcList(JcSrbcEntity jcSrbcEntity) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Page page = new Page(jcSrbcEntity.getPage(), jcSrbcEntity.getLimit());
        LambdaQueryWrapper<JcSrbcEntity> queryWrapper = Wrappers.lambdaQuery();
        if (TsBqUtils.isNotNull(jcSrbcEntity.getAjbh())) {
            queryWrapper.like(JcSrbcEntity::getAjbh, jcSrbcEntity.getAjbh());
        }
        if (TsBqUtils.isNotNull(jcSrbcEntity.getAjmc())) {
            queryWrapper.like(JcSrbcEntity::getAjmc, jcSrbcEntity.getAjmc());
        }
        if (TsBqUtils.isNotNull(jcSrbcEntity.getNsrmc())) {
            queryWrapper.like(JcSrbcEntity::getNsrmc, jcSrbcEntity.getNsrmc());
        }
        if (TsBqUtils.isNotNull(jcSrbcEntity.getNsrsbh())) {
            queryWrapper.like(JcSrbcEntity::getNsrsbh, jcSrbcEntity.getNsrsbh());
        }
        if (TsBqUtils.isNotNull(jcSrbcEntity.getZsxm())) {
            queryWrapper.like(JcSrbcEntity::getZsxm, jcSrbcEntity.getZsxm());
        }
        if (TsBqUtils.isNotNull(jcSrbcEntity.getZspm())) {
            queryWrapper.like(JcSrbcEntity::getZspm, jcSrbcEntity.getZspm());
        }
        //入库日期
        if (TsBqUtils.isNotNull(jcSrbcEntity.getRkrqq())) {
            queryWrapper.between(JcSrbcEntity::getRkrq, sdf.parse(jcSrbcEntity.getRkrqq()), sdf.parse(jcSrbcEntity.getRkrqz()));
        }
        //入库销号日期
        if (TsBqUtils.isNotNull(jcSrbcEntity.getRkxhrq())) {
            queryWrapper.between(JcSrbcEntity::getRkxhrq, sdf.parse(jcSrbcEntity.getRkxhrqq()), sdf.parse(jcSrbcEntity.getRkxhrqz()));
        }
        if (TsBqUtils.isNotNull(jcSrbcEntity.getSkssswjg())) {
            queryWrapper.like(JcSrbcEntity::getSkssswjg, jcSrbcEntity.getSkssswjg());
        }
        //税款种类
        if (TsBqUtils.isNotNull(jcSrbcEntity.getSkzl())) {
            queryWrapper.like(JcSrbcEntity::getSkzl, jcSrbcEntity.getSkzl());
        }
        if (TsBqUtils.isNotNull(jcSrbcEntity.getSksx())) {
            queryWrapper.like(JcSrbcEntity::getSksx, jcSrbcEntity.getSksx());
        }
        queryWrapper.orderByDesc(JcSrbcEntity::getRkrq);
        return this.page(page, queryWrapper);
    }

    @Override
    public List<JcSrbcEntity> exportSrbcList(JcSrbcEntity jcSrbcEntity) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        LambdaQueryWrapper<JcSrbcEntity> queryWrapper = Wrappers.lambdaQuery();
        if (TsBqUtils.isNotNull(jcSrbcEntity.getAjbh())) {
            queryWrapper.like(JcSrbcEntity::getAjbh, jcSrbcEntity.getAjbh());
        }
        if (TsBqUtils.isNotNull(jcSrbcEntity.getAjmc())) {
            queryWrapper.like(JcSrbcEntity::getAjmc, jcSrbcEntity.getAjmc());
        }
        if (TsBqUtils.isNotNull(jcSrbcEntity.getNsrmc())) {
            queryWrapper.like(JcSrbcEntity::getNsrmc, jcSrbcEntity.getNsrmc());
        }
        if (TsBqUtils.isNotNull(jcSrbcEntity.getNsrsbh())) {
            queryWrapper.like(JcSrbcEntity::getNsrsbh, jcSrbcEntity.getNsrsbh());
        }
        if (TsBqUtils.isNotNull(jcSrbcEntity.getZsxm())) {
            queryWrapper.like(JcSrbcEntity::getZsxm, jcSrbcEntity.getZsxm());
        }
        if (TsBqUtils.isNotNull(jcSrbcEntity.getZspm())) {
            queryWrapper.like(JcSrbcEntity::getZspm, jcSrbcEntity.getZspm());
        }
        //入库日期
        if (TsBqUtils.isNotNull(jcSrbcEntity.getRkrqq())) {
            queryWrapper.between(JcSrbcEntity::getRkrq, sdf.parse(jcSrbcEntity.getRkrqq()), sdf.parse(jcSrbcEntity.getRkrqz()));
        }
        //入库销号日期
        if (TsBqUtils.isNotNull(jcSrbcEntity.getRkxhrq())) {
            queryWrapper.between(JcSrbcEntity::getRkxhrq, sdf.parse(jcSrbcEntity.getRkxhrqq()), sdf.parse(jcSrbcEntity.getRkxhrqz()));
        }
        if (TsBqUtils.isNotNull(jcSrbcEntity.getSkssswjg())) {
            queryWrapper.like(JcSrbcEntity::getSkssswjg, jcSrbcEntity.getSkssswjg());
        }
        //税款种类
        if (TsBqUtils.isNotNull(jcSrbcEntity.getSkzl())) {
            queryWrapper.like(JcSrbcEntity::getSkzl, jcSrbcEntity.getSkzl());
        }
        if (TsBqUtils.isNotNull(jcSrbcEntity.getSksx())) {
            queryWrapper.like(JcSrbcEntity::getSksx, jcSrbcEntity.getSksx());
        }
        queryWrapper.orderByDesc(JcSrbcEntity::getRkrq);
        return this.list(queryWrapper);
    }
}